<@s.token name="${m}"/>
<div class="eui-panel eui-layout" data-options="fit:true">
	<div class="datagrid-toolbar" data-options="region:'north',height:'auto'" style="padding:8px">
		<a href="javascript:void(0)" class="eui-linkbutton" iconCls="icon-save" plain="true" id="savebtn">保存</a>
		<a href="javascript:void(0)" class="eui-linkbutton" iconCls="icon-expand" plain="true" id="expandbtn">展开</a>
		<a href="javascript:void(0)" class="eui-linkbutton" iconCls="icon-collapse" plain="true" id="collapsebtn">折叠</a>
		<input class="eui-textbox" style="width:120px" name="criteria.expr['rolename_like']"><a href="javascript:void(0)" class="eui-linkbutton" iconCls="icon-search" plain="true" id="searchbtn">查询</a>
	</div>
	<div class="eui-panel" data-options="region:'center',border:false">
		<ul class="eui-tree" id="tree"
			data-options="url:'${path}/eframe/framework/application/app!getAuth.action?roleId=${roleId}',
			method:'post',
			animate:false,
			checkbox:true,
			lines:true,
			onBeforeSelect:cancelSelector,
			onBeforeLoad:loadOneTime,
			onLoadSuccess:recordCheckedData">
		</ul>
	</div>
</div>
<script>
	//添加需要传递的参数
	function loadOneTime(node, param) {
		if(node) return false;
	}
	var originalIds = new List();
	function recordCheckedData() {
		new List($("#tree").tree("getChecked")).each(function(data){
			if(data.attributes.nodeType == "func") {
				originalIds.add(data.id);
			}
		});
	}
	function cancelSelector(node) {
		if(node.checked) {
			$("#tree").tree('uncheck',node.target);
		} else {
			$("#tree").tree('check',node.target);
		}
		return false;
	}
	$("#expandbtn").click(function(){
		$("#tree").tree('expandAll');
	});
	$("#collapsebtn").click(function(){
		$("#tree").tree('collapseAll');
	});
	$("#savebtn").click(function(){
		var checkedIds = new List();
		new List($("#tree").tree("getChecked")).each(function(data){
			if(data.attributes.nodeType == "func") {
				checkedIds.add(data.id);
			}
		});
		var delFuncIds = originalIds.getMyUniquePart(checkedIds);
		var addFuncIds = originalIds.getMyLackPart(checkedIds);
		var data = {roleId:"${roleId}", addFuncIds: addFuncIds.toString(), delFuncIds: delFuncIds.toString()};
		eui.ajax({
			url: "${path}/eframe/rights/etbrole/role!saveRes.action",
			token: '${m}',
			data: data,
			success:function(data){
				if(data == "token") {
					eui.msg("正在处理中...");
				} else {
					$("#partyFuncDialog").dialog("destroy");
				}				
			}
		});
	});
</script>